//
//  MSMainPetView.swift
//  MichaelToy
//
//  Created by MichaelSun on 2017/11/7.
//  Copyright © 2017年 MichaelSun. All rights reserved.
//

import UIKit


class MSMainPetView: UIView {
    
    var moveProperty = MSPetMoveProperty(speedH: 1, speedV: 1)

    func move() {
        check(frame: frame)
        frame.origin.x += CGFloat(moveProperty.speedH)
        frame.origin.y += CGFloat(moveProperty.speedV)
    }
    func check(frame: CGRect) {
        let screenHeight = UIScreen.main.bounds.size.height
        let screenWidth = UIScreen.main.bounds.size.width
        let width = frame.size.width
        let height = frame.size.height
        let x = frame.origin.x
        let y = frame.origin.y
        if x <= 0 && moveProperty.speedH < 0 {
           moveProperty.speedH = -moveProperty.speedH
        }else if x >= screenWidth - width && moveProperty.speedH > 0 {
           moveProperty.speedH = -moveProperty.speedH
        }
        if y <= 0 && moveProperty.speedV < 0 {
            moveProperty.speedV = -moveProperty.speedV
        }else if y >= screenHeight - height && moveProperty.speedV > 0 {
            moveProperty.speedV = -moveProperty.speedV
        }
        
    }
    
    
    /*
     // Only override draw() if you perform custom drawing.
     // An empty implementation adversely affects performance during animation.
     override func draw(_ rect: CGRect) {
     // Drawing code
     }
     */
    
}
